import { Component,OnDestroy } from '@angular/core';
import { IonicPage, NavController, LoadingController } from 'ionic-angular';
import { RegProvider } from './reg.provider';
/**
 * Generated class for the RegPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage({
  name:'reg'
})
@Component({
  selector: 'page-reg',
  templateUrl: 'reg.html',
  providers:[RegProvider]
})
export class RegPage implements OnDestroy{

  user:any = {
    username:'',
    password:'',
    password2:''
  };
  constructor(public navCtrl: NavController, public loadingCtrl: LoadingController,private regProvider:RegProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RegPage');
  }
  Event:any;
  submit(){
    console.log(this.user);

    let loading = this.loadingCtrl.create({
      content: 'Please wait...'
    });
  
    loading.present();

    this.Event = this.regProvider.reg(this.user).subscribe((res:any)=>{
      console.log(res);
      
      loading.dismiss();
    },(err:any)=>{
      loading.dismiss();
    },()=>{
      loading.dismiss();
    });
  
   

    // this.service.login(this.user);
  }

  ngOnDestroy(){
    if(this.Event){
      this.Event.unsubscribe();
    }
  }

}
